package com.zbmy.plugin.im.server.core;

import org.apache.log4j.Logger;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.zbmy.plugin.im.server.core.back.BackLogicService;
import com.zbmy.plugin.im.server.core.back.server.net.BackNettyServer;
import com.zbmy.plugin.im.server.core.net.NettyServer;
import com.zbmy.plugin.im.server.core.zookeeper.server.ZKServiceStore;
import com.zbmy.plugin.im.server.core.zookeeper.server.ZKUserOperator;


/**
 * 
 * 服务入口   
 * @ClassName: IMServerStartup    
 * @author Yangleping
 * @date 2018年4月28日 下午6:15:14    
 * @version  v 1.0
 */
@Component
@Order(1)//如果多个自定义ApplicationRunner，用来标明执行顺序
public class IMServerStartup implements ApplicationRunner {
	Logger logger = Logger.getLogger(IMServerStartup.class);
	/*@Override
	public void onApplicationEvent(ApplicationEvent event) {
		logger.info(event.getClass().getSimpleName() + " 事件已发生！");
		if (event instanceof ContextClosedEvent) {
			//stop();
		} else if (event instanceof ContextRefreshedEvent) {

		} else if (event instanceof ContextStartedEvent) {
			// 先启动后端逻辑服务
			//new BackLogicService().startUp();   
			// 启动netty服务，必须放在最后，这里会产生暂停
			//new NettyServer().startUp(); listen 9108  阻塞
		} else if (event instanceof ContextStoppedEvent) {
			
		} else {
			
		}
	}*/
	@Override
	public void run(ApplicationArguments args) throws Exception {
		// TODO Auto-generated method stub
		logger.info("启动Netty服务器");
		new BackLogicService().startUp();   
		new BackNettyServer().startUp();
		new NettyServer().startUp(); 
		
		ZKUserOperator.test();
	}
}
